// ScriptedEvent.cs
//
// Copyright (c) 2009 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;

using Supremacy.Game;

namespace Supremacy.Scripting
{
    [Serializable]
    public class ScriptedEvent : IGameTurnListener, IDisposable
    {
        private bool _isDisposed;

        public virtual bool CanExecute
        {
            get { return true; }
        }

        protected virtual void OnTurnStartedOverride(GameContext game) {}
        protected virtual void OnTurnPhaseStartedOverride(GameContext game, TurnPhase phase) {}
        protected virtual void OnTurnPhaseFinishedOverride(GameContext game, TurnPhase phase) {}
        protected virtual void OnTurnFinishedOverride(GameContext game) {}

        public void Dispose()
        {
            if (_isDisposed)
                return;
            try { DisposeOverride(); }
            finally { _isDisposed = true; }
        }

        protected virtual void DisposeOverride() {}

        #region Implementation of IGameTurnListener
        public void OnTurnStarted(GameContext game)
        {
            OnTurnStartedOverride(game);
        }

        public void OnTurnPhaseStarted(GameContext game, TurnPhase phase)
        {
            OnTurnPhaseStartedOverride(game, phase);
        }

        public void OnTurnPhaseFinished(GameContext game, TurnPhase phase)
        {
            OnTurnPhaseFinishedOverride(game, phase);
        }

        public void OnTurnFinished(GameContext game)
        {
            OnTurnFinishedOverride(game);
        }
        #endregion
    }
}